package com.newspublish.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newspublish.system.entity.system.ImpeachNews;
import com.newspublish.system.mapper.ImpeachNewsMapper;
import com.newspublish.system.service.ImpeachNewsService;
import com.newspublish.system.utils.result.Result;
import com.newspublish.system.utils.util.GetMassege;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Service
public class ImpeachNewsServiceImpl extends ServiceImpl<ImpeachNewsMapper,ImpeachNews> implements ImpeachNewsService {


    @Autowired
    private ImpeachNewsMapper impeachNewsMapper;

    @Autowired
    private GetMassege getMassege;

    //获取举报信息
    @Override
    public Result selectImpeachNews() {
        QueryWrapper<ImpeachNews> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("process_result","待处理");
        List<ImpeachNews> impeachNewsList=impeachNewsMapper.selectList(queryWrapper);
        return Result.ok(impeachNewsList).message("获取待处理的举报信息成功");
    }

    //通过id获取举报信息
    @Override
    public Result selectImpeachNewsById(Integer id) {
        ImpeachNews impeachNews=impeachNewsMapper.selectById(id);
        return Result.ok(impeachNews).message("获取举报信息成功");
    }

    //审核违规新闻
    @Override
    public Result impeachNews(ImpeachNews impeachNews) {
        String user= getMassege.getUser();
        impeachNews.setProcessResult("待处理");
        impeachNews.setWhistleblower(user);
        impeachNewsMapper.insert(impeachNews);
        return Result.ok().message("举报成功 将会在一到三个工作日给出答复");
    }

    //审核违规新闻
    @Override
    public Result auditor(ImpeachNews impeachNews) {
        String user=getMassege.getUser();

        return null;
    }

    //根据举报人名称获取举报信息
    @Override
    public Result getByWhistleblower() {
        String whistleblower=getMassege.getUser();
        List<ImpeachNews> impeachNewsList=impeachNewsMapper.getByWhistleblower(whistleblower);
        return Result.ok(impeachNewsList).message("获取举报信息成功");
    }

}
